package nz.co.doherty.gwtpbreadcrumbs.server.handler.product;

import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.product.ProductRetrieveAction;
import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.product.ProductRetrieveResult;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.philbeaudoin.gwtp.dispatch.server.ExecutionContext;
import com.philbeaudoin.gwtp.dispatch.server.actionHandler.ActionHandler;
import com.philbeaudoin.gwtp.dispatch.shared.ActionException;

public class ProductRetrieveHandler implements ActionHandler<ProductRetrieveAction, ProductRetrieveResult> {

	@Override
	public ProductRetrieveResult execute(ProductRetrieveAction action,
			ExecutionContext context) throws ActionException {

		Objectify ofy = ObjectifyService.begin();
		return new ProductRetrieveResult(ofy.get(action.getProductKey()));

	}

	@Override
	public void undo(ProductRetrieveAction action,
			ProductRetrieveResult result, ExecutionContext context)
			throws ActionException {
		// TODO Auto-generated method stub

	}

	@Override
	public Class<ProductRetrieveAction> getActionType() {
		return ProductRetrieveAction.class;
	}

}
